﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NRCP.App_Logic.Dummy;

namespace NRCP
{
    public partial class Farmer_List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            grvFarmers.DataSource = ProxyData.GetAllFarmers();
            grvFarmers.DataBind();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            String _name = txtFarmerLastName.Text.Trim().Replace("Search By Name", "");
            String _code = txtCode.Text.Trim().Replace("Search By Code", "");

            List<Farmers> _lists = ProxyData.GetAllFarmers();
            if (ddlStatus.SelectedItem.Value != "-1")
            {
                grvFarmers.DataSource = _lists.FindAll(obj => obj.FarmerCode.Contains(_code) && obj.Name.ToLower().Contains(_name.ToLower()));
            }
            else
            {
                grvFarmers.DataSource = _lists.FindAll(obj => obj.FarmerCode.Contains(_code) && obj.Name.ToLower().Contains(_name.ToLower()));
            }
            grvFarmers.DataBind();

        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtCode.Text = string.Empty;
            txtCode.Attributes.Add("defaultValue", "Search By Name");
            txtFarmerLastName.Text = string.Empty;
            grvFarmers.DataSource = ProxyData.GetAllFarmers();
            grvFarmers.DataBind();
        }
    }
}